﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace PhoneApp1
{
    public class EnemyItem : Item
    {
        public List<Point> Path { get; set; }
        private int CurPointNum = 0;

        public EnemyItem(GameBase game)
            : base(game)
        {
            this.x = 10;
            this.y = 10;
            this.Center = new Point(20, 20);
            this.Type = ItemType.Enemy;
            this.width = 20;
            this.height = 20;
            this.sd = 500;
            this.Path = this.Game.EnemyPath.ToList();
            //Rectangle rect = new Rectangle();
            //rect.Width = this.width;
            //rect.Height = this.height;
            //rect.Fill = new SolidColorBrush(Colors.Red);
            //this.ThisShape = rect;
            this.Game.CreateShape(this);
            this.Game.AddItem(this);
            //this.Draw();
            this.timer = new Timer(Run, null, 0, (long)this.sd);
        }

        public void Run(object state)
        {
            Draw();
        }
        public override void Draw()
        {
            //if (this.ThisShape == null)
            //{
            //    this.Game.CreateShape(this);

            //}
            base.Draw();
            var nextP = GetNextStepPoint();
            if (nextP.X == 0 && nextP.Y == 0)
            {// == null)
                this.Dispose();
                return;
            }
            this.x = (int)nextP.X-this.width/2;
            this.y = (int)nextP.Y-this.height/2;
            Path.Remove(nextP);
            this.Game.ItemRun(this);
            CurPointNum++;
            //Canvas.SetLeft(this.ThisShape, nextP.X);
            //Canvas.SetTop(this.ThisShape, nextP.Y);
            //Canvas.SetZIndex(this.ThisShape, this.z);
        }

        private Point GetNextStepPoint()
        {
            return Path.FirstOrDefault();
        }
    }
}
